package fr.uniscol.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import fr.uniscol.dao.IMatiereDao;
import fr.uniscol.model.AnneeScolaire;
import fr.uniscol.model.Matiere;

@Repository
public class MatiereDaoImpl implements IMatiereDao {

	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Matiere getMatiere(AnneeScolaire annee, String code) {
		// TODO Auto-generated method stub
		return null;
	}

	public void enregistrerMatiere(Matiere matiere) {
		Session session = sessionFactory.getCurrentSession();
		
		session.saveOrUpdate(matiere);
	}

	public List<Matiere> getAllMatieres(AnneeScolaire annee) {
		Session session = sessionFactory.getCurrentSession();
		
		Query q = session.createQuery("From Matiere Where annee_id=:annee_id");
		q.setParameter("annee_id", annee.getId());
		
		return q.list();
	}
}
